package rj.servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name="CountDisplayServlet",urlPatterns = "/CountDisplayServlet")
public class CountDisplayServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        ServletContext context = getServletContext();
        int count=Integer.parseInt(context.getAttribute("count").toString());
        context.setAttribute("count",count+1);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println("<h1>网站被访问了"+count+"次！</h1>");
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}